package top.yi2911.lifeUtils

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import java.lang.reflect.ParameterizedType

/**
 *Author:liang jian
 *Date:2021-01-14  17:43
 *Description:
 */
abstract class BaseActivity<T : ViewBinding> : AppCompatActivity(), ActivityViewInterface {

    lateinit var thisBinding: T

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val type = this.javaClass.genericSuperclass
        try {
            val thisBinding = (type as ParameterizedType).actualTypeArguments[0] as Class<T>
            val method = thisBinding.getMethod("inflate", LayoutInflater::class.java)
            this.thisBinding = method.invoke(null, layoutInflater) as T
            setContentView(this.thisBinding.root)
            initView()
            initData()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun showTitle(): Boolean {
        TODO("Not yet implemented")
    }

    override fun showLoading() {
        TODO("Not yet implemented")
    }

    override fun dismissLoading() {
        TODO("Not yet implemented")
    }

}